package com.terabits.smartriver.service.impl;

import com.alibaba.fastjson.JSON;
import com.terabits.smartriver.constants.ModelEnum;
import com.terabits.smartriver.mapper.*;
import com.terabits.smartriver.meta.dto.MongoData;
import com.terabits.smartriver.meta.po.*;
import com.terabits.smartriver.service.CalculationService;
import com.terabits.smartriver.util.CalculationUtils;
import com.terabits.smartriver.util.MongoManager;
import com.terabits.smartriver.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.security.oauth2.client.http.StringSplitUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import javax.print.DocFlavor;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static com.terabits.smartriver.util.DateUtils.StringToDate;
import static com.terabits.smartriver.util.DateUtils.getDateOnlyYMD;
import static com.terabits.smartriver.util.DateUtils.getTime;


@Service
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class CalculationServiceImpl extends BaseService implements CalculationService {
    private static final String ON = "开启";
    private static final String OFF = "关闭";

    @Resource
    private ModelMapper modelMapper;
    @Resource
    private DeviceMapper deviceMapper;
    @Resource
    private AlarmMapper alarmMapper;
    @Resource
    private MongoManager mongoManager;
    @Resource
    private MongoTemplate mongoTemplate;
    @Resource
    private ConcentrationMapper concentrationMapper;
    @Resource
    private TreatmentMapper treatmentMapper;
    @Autowired
    private DeviceMongoDataMapper deviceMongoDataMapper;
    @Autowired
    private DeviceRunTimeMapper deviceRunTimeMapper;


    @Override
    public void reportProcessing(String boxNum, String boxInterface, Object data, String closeTime, String breakTime, String createTime) {
        //1 新增mongo中一条
        MongoData mongoData = new MongoData();
        mongoData.setBoxInterface(boxInterface);
        mongoData.setData(data);
        mongoData.setCloseTime(closeTime);
        mongoData.setBreakTime(breakTime);
        mongoData.setCreateTime(createTime);
        mongoManager.save(mongoData, boxNum);
        deviceMapper.updateValueLast(boxNum, boxInterface, data, closeTime, breakTime, createTime);
        if (StringUtils.isEmpty(closeTime) && StringUtils.isEmpty(breakTime)) {
            double lastValue = Double.parseDouble(String.valueOf(data));
            if (lastValue > 0.2) {
                Device device = new Device();
                device.setBoxNum(boxNum);
                device.setBoxInterface(boxInterface);
                Device oneDevice = deviceMapper.selectOne(device);
                if (StringUtils.isEmpty(oneDevice)) {
                    return;
                }
                if (oneDevice.getIsWater() == 0 && !"仪表".equals(oneDevice.getMotor())) {
                    String deviceLastCloseTime = oneDevice.getRunTime();
                    if (StringUtils.isEmpty(deviceLastCloseTime)) {
                        if (boxNum.equals("572DLSD20190531A")) {
                            oneDevice.setRunTime(String.valueOf(20));
                        } else if (boxNum.equals("572LWHJ20190528A")) {
                            oneDevice.setRunTime(String.valueOf(20));
                        } else if (boxNum.equals("527LWHJ20191023A")) {
                            oneDevice.setRunTime(String.valueOf(60));
                        } else if (boxNum.equals("527LWHJ20191010A")) {
                            oneDevice.setRunTime(String.valueOf(30));
                        } else if (boxNum.equals("527LWHJ20191010B")) {
                            oneDevice.setRunTime(String.valueOf(30));
                        } else {
                            oneDevice.setRunTime(String.valueOf(30));
                        }

                    } else {
                        BigDecimal bigDecimal1 = null;
                        BigDecimal bigDecimal = new BigDecimal(Integer.parseInt(deviceLastCloseTime));
                        if (boxNum.equals("572DLSD20190531A")) {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("20"));
                        } else if (boxNum.equals("572LWHJ20190528A")) {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("20"));
                        } else if (boxNum.equals("527LWHJ20191023A")) {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("60"));
                        } else if (boxNum.equals("527LWHJ20191010A")) {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("30"));
                        } else if (boxNum.equals("527LWHJ20191010B")) {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("30"));
                        } else {
                            bigDecimal1 = new BigDecimal(Integer.parseInt("30"));
                        }
                        BigDecimal add = bigDecimal.add(bigDecimal1);
                        oneDevice.setRunTime(String.valueOf(add));
                    }
                    deviceMapper.updateByPrimaryKeySelective(oneDevice);
                }
            }
        }
        //最新上报数据持久化
        if (!StringUtils.isEmpty(closeTime) || !StringUtils.isEmpty(breakTime)) {
            deviceMongoDataMapper.addDeviceMongoData(boxNum, boxInterface, data, closeTime, breakTime, createTime);
        }
    }

    /**
     * 数据上报时做处理
     *
     * @param deviceNum
     * @return
     */
    @Override
    public int checkWarning(String deviceNum) {
//        PageData param = new PageData();
//        param.put("deviceNum", deviceNum);
//        List<PageData> models = modelMapper.selectModelDevice(param);
//
//        //对包含该设备的每个公式做计算判断
//        for (PageData one : models) {
//            checkSingleModel(one);
//        }
//        updateDeviceStatus(0, null);

        return 0;
    }

    @Override
    public void checkSingleModel(PageData modelDevice) {
        Integer modelId = (Integer) modelDevice.get("modelId");
        Integer mDId = (Integer) modelDevice.get("id");
        Integer res = isAnomaly(modelId, modelDevice.getString("expression"));

        if (ModelEnum.level_normal.getCode().equals(res)) {
            //检查告警记录并更新
            updateOrAddAlarm(ModelEnum.level_normal.getCode(), modelId, mDId, modelDevice.getString("devices"), res);
            System.out.println("##################################显示设备正常##################################");
        } else if (ModelEnum.level_alarm.getCode().equals(res)) {
            //做告警处理
            updateOrAddAlarm(ModelEnum.level_alarm.getCode(), modelId, mDId, modelDevice.getString("devices"), res);
            System.out.println("##################################显示设备告警##################################");
        } else if (ModelEnum.level_abnormal.getCode().equals(res)) {
            //做异常处理
            updateOrAddAlarm(ModelEnum.level_abnormal.getCode(), modelId, mDId, modelDevice.getString("devices"), res);
            System.out.println("##################################显示设备异常##################################");
        } else if (ModelEnum.level_close.getCode().equals(res)) {
            //最新上报时间超过一天做异常处理
            updateOrAddAlarm(ModelEnum.level_close.getCode(), modelId, mDId, modelDevice.getString("devices"), res);
            System.out.println("##################################存在设备最新上报时间超过一天,显示设备异常##################################");
        } else if (ModelEnum.level_k.getCode().equals(res)) {
            System.out.println("##################################该设备非模拟量设备，没有读数，不做状态修改##################################");
        } else {
            //存在设备为未激活状态,数据为空，数据为0，显示设备异常做异常处理
            updateOrAddAlarm(ModelEnum.level_abnormal.getCode(), modelId, mDId, modelDevice.getString("devices"), res);
            System.out.println("##################################存在设备为未激活状态,数据为空,数据为0,显示设备异常##################################");
        }
    }

    /**
     * 计算水量公式
     *
     * @param beginTime
     * @param endTime
     * @param projectNum
     * @return
     */
    @Override
    public String treatmentOfWater(String beginTime, String endTime, String projectNum) {
        PageData pd = new PageData();
        pd.put("projectNum", projectNum);
        List<PageData> modelDevices = modelMapper.selectModelDevice(pd);
        //就是没有给该项目配置基本公式的设备号 此处是没有配置处理水量的设备
        if (modelDevices == null || modelDevices.size() == 0) {
            return "未对项目配置设备";
        }
        double totalAmount = 0.0;
        for (PageData modelDevice : modelDevices) {
            String[] devices = modelDevice.getString("devices").split(",");
            //for循环计算所有设备
            for (String deviceNum : devices) {
                Device device = deviceMapper.selectByDeviceNum(deviceNum);
                //只计算非仪表以及非水质
                if ("仪表".equals(device.getMotor())) {
                    continue;
                }
                if (0 != device.getIsWater()) {
                    continue;
                }
                Double singleDeviceWater = singleDeviceWater(beginTime, endTime, device);
                if (singleDeviceWater == null) {
                    singleDeviceWater = 0.0;
                }
                totalAmount += singleDeviceWater;
            }
        }

        return totalAmount + "";
    }

    /**
     * 计算单个水表流量
     * 水量=时间*流量
     * 功率1=（根号3）* 380 * 电流 * 0.85   阈值判断： [上限：电机选型*1.0     下限：电机选型*0.5 ]   实时/额定
     * * 功率2=220 * 电流 * 0.85
     * 流量=功率*0.6*367/8
     * 用电量=时间*（功率*0.6*367/8）
     * <p>
     * 水量=时间(小时)*功率
     *
     * @param beginTime
     * @param endTime
     * @param device
     * @return
     */
    private Double singleDeviceWater(String beginTime, String endTime, Device device) {
        //看设备是否有接口上报数据 未绑定直接返回
        if (device.getBoxNum() == null || device.getBoxInterface() == null) {
            return null;
        }

        //时间（小时）
        Double diffHour = null;
        if (device.getBoxInterface().contains("k")) {
            diffHour = getDiffHour(beginTime, endTime, device);
            if (diffHour == null) {
                return null;
            }
        } else {
            diffHour = getDiffHourByRunTime(beginTime, endTime, device);
            if (diffHour == null) {
                return null;
            }
        }
        BigDecimal time = new BigDecimal(Double.toString(diffHour));
        BigDecimal gonglv = new BigDecimal(device.getPower());
        Double shuiliang = time.multiply(gonglv).doubleValue();
        return shuiliang;
    }

    /**
     * 获得平均电流
     *
     * @param beginTime
     * @param endTime
     * @param device
     * @return
     */
    private Double getDianliuAvg(String beginTime, String endTime, Device device) {
        Criteria criteria = Criteria.where("boxInterface").is(device.getBoxInterface()).and("createTime").gte(beginTime).lte(endTime).and("data").ne(0);

        Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(criteria),
                Aggregation.group("boxInterface").avg("data").as("data")
        );

        AggregationResults<MongoData> outputType = mongoTemplate.aggregate(agg, device.getBoxNum(), MongoData.class);
        List<MongoData> list = outputType.getMappedResults();
        if (list == null || list.size() != 1) {
            return null;
        }
        return oToD(list.get(0).getData().toString());
    }

    private Double getDiffHourByRunTime(String beginTime, String endTime, Device device) {
        String boxNum = device.getBoxNum();
        String boxInterface = device.getBoxInterface();
        DeviceRunTime deviceRunTime = new DeviceRunTime();
        deviceRunTime.setBoxNum(boxNum);
        deviceRunTime.setBoxInterface(boxInterface);
        deviceRunTime.setCreateTime(StringToDate(getTime(0).substring(0, 10), "yyyy-MM-dd"));
        DeviceRunTime deviceInfo = deviceRunTimeMapper.selectOne(deviceRunTime);
        Integer runTime = 0;
        if (deviceInfo.getRunTime() != 0) {
            runTime = deviceInfo.getRunTime();
        }
        return oToD(runTime) / 3600;
    }

    /**
     * 获得水泵用时
     *
     * @param beginTime
     * @param endTime
     * @param device
     * @return
     */
    private Double getDiffHour(String beginTime, String endTime, Device device) {
        //获取前一天设备最早一条设备开启数据
        MongoData onData = deviceMongoDataMapper.selectDeviceOnMongoData(device.getBoxNum(), device.getBoxInterface(), beginTime.substring(0, 10));
        if (StringUtils.isEmpty(onData)) {
            return null;
        }
        //获取前一天设备在设备最后一次开启之后的一条关闭数据
        //相减之后就是设备一天的开闭时间总量
        MongoData offData = deviceMongoDataMapper.selectDeviceOffMongoData(device.getBoxNum(), device.getBoxInterface(), beginTime.substring(0, 10));
        if (StringUtils.isEmpty(offData)) {
            //因为前一天没有关闭时间，所以可能设备开启之后未关闭，所以当前时间-前天最早一次开启的时间，获取时间段
            long starttime = StringToDate(onData.getCreateTime(), "").getTime();
            long endtime = StringToDate(endTime, "").getTime();
            long result = endtime - starttime;
            BigDecimal a1 = new BigDecimal(result);
            BigDecimal divide = a1.divide(new BigDecimal("1000"));
            return oToD(divide) / 3600;
        }
        return oToD((oToD(onData.getCloseTime()) - oToD(offData.getCloseTime()))) / 3600;
    }

    /**
     * 获得电流上报次数
     *
     * @param beginTime
     * @param endTime
     * @param device
     * @return
     */
    private Double getDianliuCount(String beginTime, String endTime, Device device) {
        Criteria criteria = Criteria.where("boxInterface").is(device.getBoxInterface()).and("createTime").gte(beginTime).lte(endTime).and("data").ne(0);

        Aggregation agg = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation.group("boxInterface").count().as("data"));

        AggregationResults<MongoData> outputType = mongoTemplate.aggregate(agg, device.getBoxNum(), MongoData.class);
        List<MongoData> list = outputType.getMappedResults();
        if (list == null || list.size() != 1) {
            return null;
        }
        return oToD(list.get(0).getData().toString());
    }

    /**
     * 检测公式 结果是否异常
     *
     * @param expression 限制为数值类型的公式
     * @return
     */
    private Integer isAnomaly(Integer modelId, String expression) {
        String[] split = expression.split("#");

        int size = split.length;
        if ("#".equals(expression.substring(expression.length() - 1))) {
            size++;
        }
        for (int i = 0; i < size - 1; i++) {
            String str = split[i].substring(split[i].indexOf("$")) + "#";
            //获取设备号
            String deviceNum = split[i].substring(split[i].indexOf('$') + 1);
            //得到最新读数
            String data = getDeviceValueLast(deviceNum);
            boolean timeLastReport = getDeviceTimeLastReport(deviceNum);
            if (timeLastReport) {
                return -1;
            }
            if (StringUtils.isEmpty(data)) {
                return null;
            }
            Pattern p = Pattern.compile("[\\u4e00-\\u9fa5]+");
            Matcher matcher = p.matcher(data);
            if (matcher.find() && matcher.group(0).equals(data)) {
                return -2;
            }
            //将设备号转换为读数
            expression = expression.replace(str, data);
        }
        //公式最新结果
        String result = CalculationUtils.calculation(expression);
        //查看结果范围,返回状态值
        Integer modelSettingStatus = checkLevel(modelId, Double.parseDouble(result));
        //0：正常，1:告警，2：异常
        return modelSettingStatus;
    }

    /**
     * 得到该设备的最新读数
     *
     * @param deviceNum
     * @return
     */
    private String getta(String deviceNum) {
        Device query = new Device();
        query.setDeviceNum(deviceNum);
        Device device = deviceMapper.selectOne(query);

        String[] findKeys = {"boxInterface"};
        Object[] findValues = {device.getBoxInterface()};
        MongoData one = (MongoData) mongoManager.findOne(new MongoData(), findKeys, findValues, device.getBoxNum(), "createTime");
        if (one == null) {
            return null;
        }
        return one.getData().toString();
    }

    /**
     * 得到该设备的最新读数
     *
     * @param deviceNum
     * @return
     */
    private String getDeviceValueLast(String deviceNum) {
        Device query = new Device();
        query.setDeviceNum(deviceNum);
        Device device = deviceMapper.selectOne(query);
        String valueLast = device.getValueLast();

        return valueLast;
    }

    /**
     * 得到该设备的最新上报时间是否超过一天
     *
     * @param deviceNum
     * @return
     */
    private boolean getDeviceTimeLastReport(String deviceNum) {
        Device query = new Device();
        query.setDeviceNum(deviceNum);
        Device device = deviceMapper.selectOne(query);
        Date timeLastreport = device.getTimeLastreport();
        if (StringUtils.isEmpty(timeLastreport)) {
            return true;
        }
        SimpleDateFormat localTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String beforeOneDay = getDateOnlyYMD(null, null, -1);
        Date sdate = null;
        Date deviceTimeLast = null;
        try {
            sdate = localTime.parse(beforeOneDay);
            deviceTimeLast = timeLastreport;
            if (deviceTimeLast.getTime() <= sdate.getTime()) {
                return true;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 查看该范围在什么级别内
     *
     * @param modelId
     * @param result
     * @return
     */
    private Integer checkLevel(Integer modelId, double result) {
        ModelSetting modelSetting = modelMapper.selectOneModelSetting(modelId, result);
        if (StringUtils.isEmpty(modelSetting)) {
            return 2;
        }
        return modelSetting.getStatus();
    }

    /**
     * 做异常处理 新增告警或者更新告警 或者改为正常
     *
     * @param type    0将告警解除 1新增或者修改告警
     * @param modelId
     * @param devices
     * @param res
     * @return
     */
    private int updateOrAddAlarm(Integer type, int modelId, int mDId, String devices, Integer res) {
        String[] deviceNums = devices.split(",");
        Alarm alarmInfo = new Alarm();
        alarmInfo.setModelId(modelId);
        alarmInfo.setmDId(mDId);
        alarmInfo.setResult(0);
        List<Alarm> alarms = alarmMapper.select(alarmInfo);

        //告警解除，设备状态显示正常
        if (type == 0) {
            for (String deviceNum : deviceNums) {
                //更新设备状态为正常
                Device update = new Device();
                update.setState(res);
                Example example = new Example(Device.class);
                example.createCriteria().andEqualTo("deviceNum", deviceNum);
                deviceMapper.updateByExampleSelective(update, example);
                if (alarms != null || alarms.size() != 0) {
                    //告警事件不为空，改为已解决
                    for (Alarm alarm : alarms) {
                        Alarm alarm1 = new Alarm();
                        alarm1.setTimeResult(new Date());
                        alarm1.setResult(1);
                        alarm1.setId(alarm.getId());
                        alarmMapper.updateByPrimaryKeySelective(alarm1);
                    }
                }

            }
            //告警处理
        } else if (type == 1) {
            for (String deviceNum : deviceNums) {
                //新增告警，设备状态显示告警
                if (alarms == null || alarms.size() == 0) {

                    Alarm alarm = new Alarm();
                    alarm.setModelId(modelId);
                    alarm.setmDId(mDId);
                    alarm.setDeviceNum(deviceNum);
                    alarm.setStatus(res);

                    alarmMapper.insertSelective(alarm);

                    //修改设备状态为告警状态
                    Device update = new Device();
                    update.setState(res);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);

                    //最后有一个全部状态检查。此处先注释
//                    updateDeviceStatus(1, deviceNums);
                    //更新告警
                } else {
                    for (Alarm alarm : alarms) {
                        Alarm update = new Alarm();
                        update.setTimeResult(new Date());
                        update.setStatus(res);
                        update.setResult(0);
                        update.setId(alarm.getId());
                        alarmMapper.updateByPrimaryKeySelective(update);
                    }
                    //修改设备状态为告警状态
                    Device update = new Device();
                    update.setState(res);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);
                }

            }
            //最新上报时间超过一天
        } else if (type == -1) {
            for (String deviceNum : deviceNums) {
                //无告警事件的话只需更新设备状态即可
                if (alarms == null || alarms.size() == 0) {
                    Alarm alarm = new Alarm();
                    alarm.setModelId(modelId);
                    alarm.setmDId(mDId);
                    alarm.setDeviceNum(deviceNum);
                    alarm.setStatus(3);

                    alarmMapper.insertSelective(alarm);
                    //修改设备状态为离线状态
                    Device update = new Device();
                    update.setState(3);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);
                    //有告警事件，就更新告警为离线
                } else {
                    for (Alarm alarm : alarms) {
                        Alarm update = new Alarm();
                        update.setTimeResult(new Date());
                        update.setStatus(3);
                        update.setResult(0);
                        update.setId(alarm.getId());
                        alarmMapper.updateByPrimaryKeySelective(update);
                    }
                    //并且修改设备状态为离线状态
                    Device update = new Device();
                    update.setState(3);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);
                }
            }
        } else {
            for (String deviceNum : deviceNums) {
                //新增异常，设备状态显示异常
                if (alarms == null || alarms.size() == 0) {

                    Alarm alarm = new Alarm();
                    alarm.setModelId(modelId);
                    alarm.setmDId(mDId);
                    alarm.setDeviceNum(deviceNum);
                    alarm.setStatus(2);

                    alarmMapper.insertSelective(alarm);
                    //修改设备状态为异常状态
                    Device update = new Device();
                    update.setState(2);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);

                    //最后有一个全部状态检查。此处先注释
//                    updateDeviceStatus(1, deviceNums);
                    //更新异常
                } else {
                    for (Alarm alarm : alarms) {
                        Alarm update = new Alarm();
                        update.setTimeResult(new Date());
                        update.setStatus(2);
                        update.setResult(0);
                        update.setId(alarm.getId());
                        alarmMapper.updateByPrimaryKeySelective(update);
                    }
                    //修改设备状态为异常状态
                    Device update = new Device();
                    update.setState(2);
                    Example example = new Example(Device.class);
                    example.createCriteria().andEqualTo("deviceNum", deviceNum);
                    deviceMapper.updateByExampleSelective(update, example);

                }

            }
        }
        return 0;


    }

    /**
     * 将设备状态改为异常中
     *
     * @param type       0检查更新状态。1状态更改为异常
     * @param deviceNums
     */
    @Override
    public void updateDeviceStatus(Integer type, String[] deviceNums) {
        if (type == 0) {
            deviceMapper.checkDeviceStatus();
            return;
        }

        Device update = new Device();
        update.setState(1);
        for (String deviceNum : deviceNums) {
            Example example = new Example(Device.class);
            example.createCriteria().andEqualTo("deviceNum", deviceNum);
            deviceMapper.updateByExampleSelective(update, example);
        }
    }

    @Override
    public int addTreatment(Treatment treatment) {
        return treatmentMapper.insertSelective(treatment);
    }

    @Override
    public PageData getTreatment(String beginTime, String endTime, String projectNum) {
        PageData water = treatmentMapper.selectTreatmentOfWater(projectNum, beginTime, endTime);
        return water;
    }

    @Override
    public Integer getTreatment(String projectNum) {
        return treatmentMapper.selectTreatmentOfCount(projectNum);
    }

    @Override
    public Concentration getConcentration(String projectNum, String Date, Integer type) {
        Concentration query = new Concentration();
        query.setProjectNum(projectNum);
        query.setType(type);
        query.setDate(Date);
        return concentrationMapper.selectOne(query);
    }

    @Override
    public Concentration getConcentrationOne(String projectNum, Integer type) {
        Concentration query = new Concentration();
        query.setProjectNum(projectNum);
        query.setType(type);
        return concentrationMapper.getConcentrationOne(query);
    }
}
